<?php
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Model\OperationLogs;
use App\Model\Equip;
use Illuminate\Foundation\Console\Presets\React;

class EquipController extends BaseController
{

    protected $model = null;
    /**
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->model = new Equip();
    }

    //装备列表
    public function equipList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->equipList($request));
    }

    //获取装备类型
    public function getEquipType(Request $request){
        $res = $this->model->getEquipType($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //编辑装备
    public function editEquip(Request $request){
        $res = $this->model->editEquip($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //装备货架列表
    public function equipShelveList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->equipShelveList($request));
    }

    //装备货架新增
    public function addEquipShelve(Request $request){
        $res = $this->model->addEquipShelve($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //装备货架编辑
    public function editEquipShelve(Request $request){
        $res = $this->model->editEquipShelve($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //装备货架删除
    public function delEquipShelve(Request $request){
        $res = $this->model->delEquipShelve($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //编辑装备类型
    public function editEquipType(Request $request){
        $res = $this->model->editEquipType($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星游戏列表
    public function getGameList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getGameList());
    }

    //开运装备星游戏配置修改
    public function gameEdit(Request $request){
        $res = $this->model->gameEdit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星经游戏配置修改');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星游戏开启/关闭
    public function gameStatus(Request $request){
        $res = $this->model->gameStatus($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星游戏开启/关闭');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星一级奖池列表
    public function getPollOneList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getPollOneList($request));
    }

    //开运装备星一级奖池新增
    public function pollOneAdd(Request $request){
        $res = $this->model->pollOneAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星一级奖池新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星一级奖池修改
    public function pollOneEdit(Request $request){
        $res = $this->model->pollOneEdit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星一级奖池修改');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星一级奖池删除
    public function pollOneDel(Request $request){
        $res = $this->model->pollOneDel($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星一级奖池删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星二级奖池列表
    public function getPollTwoList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getPollTwoList($request));
    }

    //开运装备星二级奖池新增
    public function pollTwoAdd(Request $request){
        $res = $this->model->pollTwoAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星二级奖池新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星二级奖池修改
    public function pollTwoEdit(Request $request){
        $res = $this->model->pollTwoEdit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星二级奖池修改');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星二级奖池删除
    public function pollTwoDel(Request $request){
        $res = $this->model->pollTwoDel($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星二级奖池删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单列表
    public function whiteList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getWhiteList($request));
    }

    //开运装备星白名单新增
    public function whiteAdd(Request $request){
        $res = $this->model->whiteAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单修改
    public function whiteEdit(Request $request){
        $res = $this->model->whiteEdit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单修改');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单删除
    public function whiteDelete(Request $request){
        $res = $this->model->whiteDelete($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单配置列表
    public function whiteConfigList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getWhiteConfigList($request));
    }

    //开运装备星白名单配置新增
    public function whiteConfigAdd(Request $request){
        $res = $this->model->whiteConfigAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单配置新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单配置删除
    public function whiteConfigDelete(Request $request){
        $res = $this->model->whiteConfigDelete($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单配置删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单用户列表
    public function whiteUserList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getWhiteUserList($request));
    }

    //开运装备星白名单配置新增
    public function whiteUserAdd(Request $request){
        $res = $this->model->whiteUserAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单用户新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星白名单用户删除
    public function whiteUserDelete(Request $request){
        $res = $this->model->whiteUserDelete($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '开运装备星白名单用户删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //开运装备星统计数据概述
    public function statSearchAll(Request $request){
        $res = $this->model->statSearchAll($request);
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //开运装备星指定用户挑战记录
    public function userDrawList(Request $request){
        $res = $this->model->userDrawList($request);
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //开运装备星奖励产出查询
    public function statPoolItem(Request $request){
        $res = $this->model->statPoolItem($request);
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //开运装备星奖励产出详情查询
    public function statPoolItemDetail(Request $request){
        $res = $this->model->statPoolItemDetail($request);
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //开运装备星用户参与排行
    public function statUserOrder(Request $request){
        $res = $this->model->statUserOrder($request);

        return $this->toJson(self::SUCCESS, $res);
    }

    //拍卖行数据统计
    public function equipAuctionStatistics(Request $request){
        $res = $this->model->getEquipAuctionStatistic();
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //拍卖行详情
    public function equipAuctionList(Request $request){
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $sale_status = $request->get('sale_status',0);//0全部1=出售中 2=已出售 3=下架 

        $start_time = $request->get('start_time','');//开始时间
        $end_time = $request->get('end_time','');//结束时间
        $equipType = $request->get('equipType',0);//0全部 1=头部2=上衣 3=披风 4=武器 5=下装 6=鞋子 7=装饰 8=套装 9=脸型 
        $saleUid = $request->get('saleUid',0);//出售用户uid 
        $un_uuid = $request->get('un_uuid',0);//公会长uid 


        $res = $this->model->getEquipAuctionList($page, $limit, $sale_status, $start_time, $end_time, $equipType, $saleUid, $un_uuid);
        if(isset($res['code'])) {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, $res);
    }

    //后台-拍卖行下架
    public function equipAuctionUnsale(Request $request){
        $auctionId = $request->get('auction_id');//拍卖行id
        if(empty($auctionId)){
            return $this->toJson(self::PARAM_ERROR, [], '缺少参数');
        }
        $status = $this->model->unSaleAuction($auctionId);
        if($status['code'] == 0){
            return $this->toJson(self::SUCCESS);
        }else{
            return $this->toJson(self::ERROR,[],$status['msg']);
        }
    }

    //后台-拍卖行系统回收配置
    public function equipAuctionSysConfig(){
        $res = $this->model->equipSysConfig();
        return $this->toJson(self::SUCCESS,$res);
    }

    //后台-拍卖行系统回收配置-禁用用户
    public function equipAuctionUpSysConfig(Request $request){
        $status = $request->post('status',0); //1启用2禁用
        $id = $request->post('id',0);//修改的id
        if(empty($id)){
            return $this->toJson(self::ERROR,[],'缺少id');
        }
        if(empty($status)){
            return $this->toJson(self::ERROR,[],'缺少参数');
        }
        $this->model->updateSysConfig($status,$id);
        return $this->toJson(self::SUCCESS);
    }

    //后台-拍卖行新增回收用户
    public function equipAuctionAddSysConfig(Request $request){
        $userid = $request->post('user_id',0);
        if(empty($userid)){
            return $this->toJson(self::ERROR,[],'缺少参数');
        }
        $minutes = $request->post('minutes',10);//默认回收时间
        $this->model->AddSysConfig($userid,$minutes);
        return $this->toJson(self::SUCCESS);
    }

    //后台-增加系统回收用户金豆数
    public function equipAuctionAddSysUserJd(Request $request){
        $id = $request->post('id',0);//修改的id
        if(empty($id)){
            return $this->toJson(self::ERROR,[],'缺少id');
        }
        $nums = $request->post('nums',0);//金豆数
        if(empty($nums)){
            return $this->toJson(self::ERROR,[],'缺少金豆数');
        }
        $res = $this->model->equipAuctionAddSysUserJd($id,$nums);
        if($res['code'] != 0){
            return $this->toJson(self::ERROR,[],$res['msg']);
        }
        return $this->toJson(self::SUCCESS);
    }

    //后台-增加修改系统聊天配置
    public function equipAuctionChatConfig(Request $request){
        $id = $request->post('id',0);
        $mic_all_time = $request->post('mic_all_time',0);//主播在线时长
        $min_rich_value = $request->post('min_rich_value',0);//主播财富值
        $max_rich_value = $request->post('max_rich_value',0);//主播最大财富值
        $min_charm_value = $request->post('min_charm_value',0);//主播最小魅力值
        $max_charm_value = $request->post('max_charm_value',0);//主播最大魅力值
        $min_user_rich_value = $request->post('min_user_rich_value',0);//用户最小财富值
        $max_user_rich_value = $request->post('max_user_rich_value',0);//用户最大财富值
        $max_user_recharge_value = $request->post('max_user_recharge_value',0);//用户最大充值数
        $min_user_recharge_value = $request->post('min_user_recharge_value',0);//用户最小充值数
        $after_day = $request->post('after_day',0);//注册x天后
        $status = $request->post('status',0);//1启用 2关闭

        $status = $this->model->equipAuctionChangeChatConfig($id, $mic_all_time, $min_rich_value, $max_rich_value, $min_charm_value, $max_charm_value, $min_user_rich_value, $max_user_rich_value, $min_user_recharge_value,$max_user_recharge_value,$after_day,$status);
        return $this->toJson(self::SUCCESS);
    }

    //后台-拍卖公聊厅准入配置列表
    public function equipAuctionChatList(Request $request){
        $page = $request->get('page',1);//分页
        $limit = $request->get('limit',10);//分页数
        $data = $this->model->equipAuctionChangeChatList($page, $limit);
        return $this->toJson(self::SUCCESS,$data);
    }

    //拍卖公聊厅举报列表
    public function equipAuctionChatReport(Request $request){
        $page = $request->get('page',1);//分页
        $limit = $request->get('limit',10);//分页数
        $date = $request->get('date','');//时间
        $user_id = $request->get('user_id',0);//用户id
        $user_name = $request->get('user_name','');//用户名称
        $data = $this->model->equipAuctionChatReport($page, $limit, $date, $user_id, $user_name);
        return $this->toJson(self::SUCCESS,$data);
    }

    //拍卖公聊举报处理
    public function equipAuctionChatReportChange(Request $request){
        $id = $request->post('id',0);//举报id
        $admin_id = $request->post('admin_id',0);//操作人id
        if(empty($id)){
            return $this->toJson(self::PARAM_ERROR);
        }
        $type = $request->post('type',0);//处理类型
        $time = $request->post('hour',0);//封禁时长
        $this->model->equipAuctionChatReportChange($id, $type, $time, $admin_id);
        return $this->toJson(self::SUCCESS);
    }
}
